# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=protobuf-c
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.4.1
pkgrel=2
pkgdesc="Protocol Buffers implementation in C (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/protobuf-c/protobuf-c"
license=('spdx:BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-protobuf")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
source=("$url/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-fix-build-with-protobuf-23.patch")
sha256sums=('4cc4facd508172f3e0a4d3a8736225d472418aee35b4ad053384b137b220339f'
            'b9c157f334f5933d8142821de585fa93b9801fb079fba309d4d4803e891d67d9')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  # https://github.com/protobuf-c/protobuf-c/pull/673
  patch -p1 -i "${srcdir}"/001-fix-build-with-protobuf-23.patch
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST}

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE
}
